package com.igeek.d0613.test1;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: zhiyu
 * @Date:16:58
 * @DESC:
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        //共同资源
        List<Object> num = new CopyOnWriteArrayList<>();
        //创建生产者线程
        ProductThread productThread1 = new ProductThread("生产者A", num);
        ProductThread productThread2 = new ProductThread("生产者B", num);
        //创建消费者线程
        ConsumerThread consumerThread1 = new ConsumerThread("消费者C", num);
        ConsumerThread consumerThread2 = new ConsumerThread("消费者D", num);
        productThread1.setConsumer(consumerThread1);
        productThread1.setConsumer(consumerThread2);
        productThread2.setConsumer(consumerThread1);
        productThread2.setConsumer(consumerThread2);
        consumerThread1.setProduct(productThread1);
        consumerThread1.setProduct(productThread2);
        consumerThread2.setProduct(productThread1);
        consumerThread2.setProduct(productThread2);
        //开启线程
        productThread1.start();
        productThread2.start();
        consumerThread1.start();
        consumerThread2.start();
    }
}
